---
title: "Oauth"
description: "Oauth API Documentation"
icon: "code"
github: "https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/auth/oauth.py"
---

import {RandomGradientBackground} from "/snippets/gradient.jsx"

<Callout type="info" title="Source Code">
View the source code for this module on GitHub: <a href='https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/auth/oauth.py' target='_blank' rel='noopener noreferrer'>https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/auth/oauth.py</a>
</Callout>

## OAuth

<div>
<RandomGradientBackground className="rounded-lg p-4 w-full h-full rounded-full">
<div className="text-black">
<div className="text-black font-bold text-xl mb-2 mt-8"><code className="!text-black">class</code> OAuth</div>

</div>
</RandomGradientBackground>
```python
from mcp_use.auth.oauth import OAuth
```

<Card type="info">
### `method` __init__

Initialize OAuth handler.


**Parameters**
><ParamField body="server_url" type="str" required="True" >   The MCP server URL </ParamField>
><ParamField body="token_storage" type="mcp_use.client.auth.oauth.FileTokenStorage | None" default="None" >   Token storage implementation. Defaults to FileTokenStorage </ParamField>
><ParamField body="scope" type="str | None" default="None" >   OAuth scopes to request </ParamField>
><ParamField body="client_id" type="str | None" default="None" >   OAuth client ID. If not provided, will attempt dynamic registration </ParamField>
><ParamField body="client_secret" type="str | None" default="None" >   OAuth client secret (for confidential clients) </ParamField>
><ParamField body="callback_port" type="int | None" default="None" >   Port for local callback server, if empty, 8080 is used </ParamField>
><ParamField body="oauth_provider" type="mcp_use.client.auth.oauth.OAuthClientProvider | None" default="None" >   OAuth client provider to prevent metadata discovery </ParamField>

**Signature**
```python wrap
def __init__(server_url: str, token_storage: mcp_use.client.auth.oauth.FileTokenStorage | None = None, scope: str | None = None, client_id: str | None = None, client_secret: str | None = None, callback_port: int | None = None, oauth_provider: mcp_use.client.auth.oauth.OAuthClientProvider | None = None):
```

</Card>
</div>
